]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
messageTray: Add action-added/action-removed signals to Notification
authorJulian Sparber <julian@sparber.net>
Wed, 14 Feb 2024 14:45:50 +0000 (15:45 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Sun, 3 Mar 2024 01:33:16 +0000 (01:33 +0000)
Add signals so that the message actor can update the it's action when
they change.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3173>

js/ui/messageTray.js

index d7d21f6664a59d4949944e55fc536ea1f4a69036..72db9579e0f4195cd936465e4cfa00077c6df394 100644 (file)
@@ -333,6 +333,24 @@ class Sound extends GObject.Object {
     }
 });
 
+export const Action = GObject.registerClass(
+class Action extends GObject.Object {
+    constructor(label, callback) {
+        super();
+
+        this._label = label;
+        this._callback = callback;
+    }
+
+    get label() {
+        return this._label;
+    }
+
+    activate() {
+        this._callback();
+    }
+});
+
 // Notification:
 // @source: the notification's Source
 // @title: the title
@@ -393,6 +411,8 @@ export const Notification = GObject.registerClass({
             false),
     },
     Signals: {
+        'action-added': {param_types: [Action]},
+        'action-removed': {param_types: [Action]},
         'activated': {},
         'destroy': {param_types: [GObject.TYPE_UINT]},
         'updated': {param_types: [GObject.TYPE_BOOLEAN]},
@@ -453,7 +473,7 @@ export const Notification = GObject.registerClass({
             this.gicon = params.gicon;
 
         if (params.clear)
-            this.actions = [];
+            this.clearActions();
 
         if (this.sound !== params.sound) {
             this.sound = params.sound;
@@ -478,7 +498,19 @@ export const Notification = GObject.registerClass({
     // @label: the label for the action's button
     // @callback: the callback for the action
     addAction(label, callback) {
-        this.actions.push({label, callback});
+        const action = new Action(label, callback);
+        this.actions.push(action);
+        this.emit('action-added', action);
+    }
+
+    clearActions() {
+        if (this.actions.length === 0)
+            return;
+
+        this.actions.forEach(action => {
+            this.emit('action-removed', action);
+        });
+        this.actions = [];
     }
 
     setUrgency(urgency) {
@@ -573,7 +605,7 @@ export const NotificationBanner = GObject.registerClass({
 
     _addActions() {
         this.notification.actions.forEach(action => {
-            this.addAction(action.label, action.callback);
+            this.addAction(action.label, () => action.activate());
         });
     }